/**
 * @author Benny Yang
 * @since 20161115 地图中搜索地点附近信息操作
 * 
 * 附近景点是2000m范围，饭店是500米范围，酒店是1000米范围
 * 
 */
var map = null;
var centerPP = null;
var weatherData = null;
var searchResult1 = null;// 保存搜索结果
var currCity = '北京';// 当前地图显示区域所在城市，默认为北京
var currDistrict = '北京';// 当前县级行政单位

// 在全局范围设置变量保存搜索结果
var resultArray = new Array();
var resultArray1 = new Array();
var resultArray2 = new Array();

// 定义全局数组，保存所有检索结果，作为数据接口传输
var searchLocalArr = new Array();
function G(id) {
	return document.getElementById(id);
}

function onLoadFunc() {

	// changelog 20170308页面初始化时显示的城市应该为上游页面传递的地点

	var locCity = GetQueryString("loc");

//	alert('locCity为000：' + locCity);

	if (locCity == null) {

		setWeather(currDistrict);
		map = new BMap.Map("l-map");
		map.centerAndZoom('北京', 12); // 初始化地图,设置城市和地图级别。
		map.enableScrollWheelZoom(true);// 设置地图可以滚动缩放
		var top_left_control = new BMap.ScaleControl({
			anchor : BMAP_ANCHOR_TOP_LEFT
		});// 左上角，添加比例尺
		var top_left_navigation = new BMap.NavigationControl(); // 左上角，添加默认缩放平移控件

		map.addControl(top_left_control);
		map.addControl(top_left_navigation);
		var myDis = new BMapLib.DistanceTool(map);
		map.addEventListener("load", function() {
			// myDis.open(); //开启鼠标测距
			// myDis.close(); //关闭鼠标测距大
		});
		autoCompleteFunc(map);
	} else {

		map = new BMap.Map("l-map");
		map.centerAndZoom(locCity, 12); // 初始化地图,设置城市和地图级别。
		map.enableScrollWheelZoom(true);// 设置地图可以滚动缩放
		var top_left_control = new BMap.ScaleControl({
			anchor : BMAP_ANCHOR_TOP_LEFT
		});// 左上角，添加比例尺
		var top_left_navigation = new BMap.NavigationControl(); // 左上角，添加默认缩放平移控件

		map.addControl(top_left_control);
		map.addControl(top_left_navigation);
		var myDis = new BMapLib.DistanceTool(map);
		map.addEventListener("load", function() {
			// myDis.open(); //开启鼠标测距
			// myDis.close(); //关闭鼠标测距大
		});
		autoCompleteFunc(map);

		// alert('传递的参数为：' + locCity);

		setPlace(locCity);
		$("#suggestId").val(locCity);

	}

	// 构建自动补全功能的组件

}

function autoCompleteFunc(mapInstance) {

	var ac = new BMap.Autocomplete( // 建立一个自动完成的对象
	{
		"input" : "suggestId",
		"location" : mapInstance
	});

	// setWeather(currDistrict);
	ac.addEventListener("onhighlight", function(e) { // 鼠标放在下拉列表上的事件
		var str = "";
		var _value = e.fromitem.value;
		var value = "";
		if (e.fromitem.index > -1) {
			value = _value.province + _value.city + _value.district
					+ _value.street + _value.business;
		}
		str = "FromItem<br />index = " + e.fromitem.index + "<br />value = "
				+ value;

		value = "";
		if (e.toitem.index > -1) {
			_value = e.toitem.value;
			value = _value.province + _value.city + _value.district
					+ _value.street + _value.business;
		}
		str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = "
				+ value;
		G("searchResultPanel").innerHTML = str;
	});

	var myValue;
	ac.addEventListener("onconfirm", function(e) { // 鼠标点击下拉列表后的事件
		var _value = e.item.value;
		myValue = _value.province + _value.city + _value.district
				+ _value.street + _value.business;
		G("searchResultPanel").innerHTML = "onconfirm<br />index = "
				+ e.item.index + "<br />myValue = " + myValue;

		setPlace(myValue);
	});

	// ----------------------------------------起点终点下拉菜单
	var ac1 = new BMap.Autocomplete( // 建立一个自动完成的对象
	{
		"input" : "start",
		"location" : mapInstance
	});
	ac1.addEventListener("onhighlight", function(e) { // 鼠标放在下拉列表上的事件
		var str = "";
		var _value = e.fromitem.value;
		var value = "";
		if (e.fromitem.index > -1) {
			value = _value.province + _value.city + _value.district
					+ _value.street + _value.business;
		}
		str = "FromItem<br />index = " + e.fromitem.index + "<br />value = "
				+ value;

		value = "";
		if (e.toitem.index > -1) {
			_value = e.toitem.value;
			value = _value.province + _value.city + _value.district
					+ _value.street + _value.business;
		}
		str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = "
				+ value;
		G("searchResultPanel").innerHTML = str;
	});

	var myValue;
	ac1.addEventListener("onconfirm", function(e) { // 鼠标点击下拉列表后的事件
		var _value = e.item.value;
		myValue = _value.province + _value.city + _value.district
				+ _value.street + _value.business;
		G("searchResultPanel").innerHTML = "onconfirm<br />index = "
				+ e.item.index + "<br />myValue = " + myValue;

		// setPlace(myValue);
	});
	var ac2 = new BMap.Autocomplete( // 建立一个自动完成的对象
	{
		"input" : "end",
		"location" : mapInstance
	});
	ac2.addEventListener("onhighlight", function(e) { // 鼠标放在下拉列表上的事件
		var str = "";
		var _value = e.fromitem.value;
		var value = "";
		if (e.fromitem.index > -1) {
			value = _value.province + _value.city + _value.district
					+ _value.street + _value.business;
		}
		str = "FromItem<br />index = " + e.fromitem.index + "<br />value = "
				+ value;

		value = "";
		if (e.toitem.index > -1) {
			_value = e.toitem.value;
			value = _value.province + _value.city + _value.district
					+ _value.street + _value.business;
		}
		str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = "
				+ value;
		G("searchResultPanel").innerHTML = str;
	});

	var myValue;
	ac2.addEventListener("onconfirm", function(e) { // 鼠标点击下拉列表后的事件
		var _value = e.item.value;
		myValue = _value.province + _value.city + _value.district
				+ _value.street + _value.business;
		G("searchResultPanel").innerHTML = "onconfirm<br />index = "
				+ e.item.index + "<br />myValue = " + myValue;

		// setPlace(myValue);
	});

}
// -------------------------------------

/**
 * setPlace方法功能主要有根据搜索结果重新构建当地地图，显示所搜索地点附近的景点，餐馆，以及当地天气预报
 */
function setPlace(inputedValue) {
	map.clearOverlays(); // 清除地图上所有覆盖物

	var local = new BMap.LocalSearch(map, { // 智能搜索
		onSearchComplete : myFun
	});
	local.search(inputedValue);

	// 希望在搜索完成之后对标签添加属性
}

function myFun(result) {
	// var pp = local.getResults().getPoi(0).point; //获取第一个智能搜索的结果
	var pp = result.getPoi(0).point; // 获取第一个智能搜索的结果

	centerPP = pp;
	map.centerAndZoom(pp, 18);

	// 设置天气
	// 获取当前point所在城市
	$.ajaxSettings.async = false;
	var geoCoder = new BMap.Geocoder();
	geoCoder.getLocation(pp, function(rs) {

		var addComp = rs.addressComponents;
		// currCity = addComp.district;
		currCity = addComp.city;
		currDistrict = addComp.district;
		// var currCity1 = currCity.substr(0,currCity.length-1);
		// alert("currDistrict:"+currDistrict+"------currCity:"+currCity);
		setWeather(currDistrict);

	});

	var marker = new BMap.Marker(pp);
	map.addOverlay(marker); // 添加标注
	marker.setAnimation(BMAP_ANIMATION_BOUNCE); // 跳动的动画

	/*
	 * var circle = new BMap.Circle(pp, 2000, { fillColor : "blue", strokeWeight :
	 * 1, fillOpacity : 0.3, strokeOpacity : 0.3 }); map.addOverlay(circle);
	 */

	var myIcon = new BMap.Icon("../images/marker1.png", new BMap.Size(20, 40),
			{
				offset : new BMap.Size(0, 0), // 指定定位位置
				imageOffset : new BMap.Size(-5, -5)
			});// 设置景点标志marker
	var myIcon2 = new BMap.Icon("../images/marker2.png", new BMap.Size(20, 40),
			{
				offset : new BMap.Size(0, 0), // 指定定位位置
				imageOffset : new BMap.Size(0, 0)
			});// 设置图片偏移 ;//设置餐厅标志marker

	// 需要在此周围再次进行搜索景点和餐厅
	/*
	 * var local1 = new BMap.LocalSearch(map,
	 * {renderOptions:{map:map,panel:"jingdianListDiv"},pageCapacity:4,
	 * onSearchComplete: function(result){
	 * 
	 * for(var i=0;i<result.getCurrentNumPois();i++){//遍历搜索结果，在地图上标识出来
	 * 
	 * var marker = new BMap.Marker(result.getPoi(i).point,{icon:myIcon});
	 * 
	 * 
	 * map.addOverlay(marker); //添加标注 } } });
	 */

	getNearPoi('pageIndex', '景点', 2000);
	getNearPoiData('景点', 2000);
	/*
	 * getNearPoi('pageIndex1', '美食',centerPP,1000);
	 * getNearPoiData('景点',centerPP,1000); getNearPoi('pageIndex2',
	 * '酒店',centerPP,1000); getNearPoiData('景点',centerPP,1000);
	 */
	// 使用onResultsHtmlSet回调函数设置条目标签点击时的动作响应，并获取其中景点名称
	/*
	 * var local1 = new BMap.LocalSearch(map, { renderOptions : { map : map, //
	 * panel : "jingdianListDiv" panel : "pageIndex" }, onResultsHtmlSet :
	 * function(container) {
	 * 
	 * $(container).find("li>div").attr("onclick", "chooseItem(this);"); //
	 * alert("origOnclickFuncs：" + origOnClickFuncs);
	 *  }, pageCapacity : 8 }); local1.searchNearby('景点', pp, 2000);
	 */

	/*
	 * var local2 = new BMap.LocalSearch(map, { renderOptions : { map : map, //
	 * panel : "jingdianListDiv" panel : "pageIndex1" }, onResultsHtmlSet :
	 * function(container) {
	 * 
	 * $(container).find("li>div").attr("onclick", "chooseItem(this);"); },
	 * pageCapacity : 8 }); local2.searchNearby('美食', pp, 1000);
	 * 
	 * var local3 = new BMap.LocalSearch(map, { renderOptions : { map : map, //
	 * panel : "jingdianListDiv" panel : "pageIndex2" }, onResultsHtmlSet :
	 * function(container) {
	 * 
	 * $(container).find("li>div").attr("onclick", "chooseItem(this);"); },
	 * pageCapacity : 8 }); local3.searchNearby('酒店', pp, 1000);
	 */
}

/**
 * @author Benny Yang
 * @since 20161121 根据传入的坐标，调用第三方api设置天气情况显示
 * @param currentCity
 */
function setWeather(currentCity) {

	$.ajaxSettings.async = false;
	getWeatherData(currentCity);
	// $("#weatherDiv").text(JSON.stringify(weatherData));
	// 获取天气详情，解析 json数据，在页面显示天气情况。

}

/**
 * 使用jquery ajax获取远程url上的天气信息
 * 
 * @param currentCity//需要查询天气的城市
 */
function getWeatherData(currentCity) {

	var getData = function(currLoc) {
		$
				.ajax({
					async : false,
					type : "GET",
					dataType : 'jsonp',
					jsonp : 'callback',
					jsonpCallback : 'callbackfunction',
					url : "http://api.map.baidu.com/telematics/v3/weather?access-control-allow-origin=true&output=json&ak=uTj0rZfVxBUnHBaQnX4ZXulWFynKEpdY&location="
							+ currLoc,
					data : "",
					timeout : 3000,
					contentType : "application/json;utf-8",
					success : function(msg) {
						// 设置天气显示窗口显示内容

						if (msg.error != 0 || msg.status != 'success') {

							// alert('当前区县查询不到天气信息，执行市级天气查询...'+currCity);
							getData(currCity);
						} else {

							weatherData = msg;

							showWeatherInfo(msg);
						}

					}
				});
	}

	getData(currentCity);

}

function callbackfunction() {

}

/**
 * 友好化显示查询的天气结果
 * 
 * @author Benny Yang
 * @since 20161123
 * @param jsonInfo
 *            返回的json格式的数据
 */
function showWeatherInfo(jsonInfo) {
	// var jsonInfo1 = eval(jsonInfo);
	// alert("test json读取数据:"+JSON.stringify(jsonInfo));
	// alert("test json读取数据:详细数据访问："+jsonInfo.results[0].index[0].des);
	$("#currentCity").text(jsonInfo.results[0].currentCity + "天气预报");
	$("#currentCityTips").text(jsonInfo.results[0].currentCity + "生活指南");
	$("#futureWeather").text(jsonInfo.results[0].currentCity + "未来3日天气");

	$("#todayDate").text(jsonInfo.date);
	$("#todayWeatherImage").attr('src',
			jsonInfo.results[0].weather_data[0].dayPictureUrl);// 当前天气对应的图标
	$("#todayTemp").text(jsonInfo.results[0].weather_data[0].temperature);
	$("#todayWeather").text(jsonInfo.results[0].weather_data[0].weather);
	$("#todayWind").text(jsonInfo.results[0].weather_data[0].wind);

	// 设置后几天的天气情况
	$("#date1").text(jsonInfo.results[0].weather_data[1].date);
	$("#weatherImage1").attr('src',
			jsonInfo.results[0].weather_data[1].dayPictureUrl);// 当前天气对应的图标
	$("#temp1").text(jsonInfo.results[0].weather_data[1].temperature);
	$("#weather1").text(jsonInfo.results[0].weather_data[1].weather);
	$("#wind1").text(jsonInfo.results[0].weather_data[1].wind);

	$("#date2").text(jsonInfo.results[0].weather_data[2].date);
	$("#weatherImage2").attr('src',
			jsonInfo.results[0].weather_data[2].dayPictureUrl);// 当前天气对应的图标
	$("#temp2").text(jsonInfo.results[0].weather_data[2].temperature);
	$("#weather2").text(jsonInfo.results[0].weather_data[2].weather);
	$("#wind2").text(jsonInfo.results[0].weather_data[2].wind);

	$("#date3").text(jsonInfo.results[0].weather_data[3].date);
	$("#weatherImage3").attr('src',
			jsonInfo.results[0].weather_data[3].dayPictureUrl);// 当前天气对应的图标
	$("#temp3").text(jsonInfo.results[0].weather_data[3].temperature);
	$("#weather3").text(jsonInfo.results[0].weather_data[3].weather);
	$("#wind3").text(jsonInfo.results[0].weather_data[3].wind);

	var todayDetailText = jsonInfo.results[0].currentCity + "今天温度 "
			+ jsonInfo.results[0].weather_data[0].temperature + ", "
			+ jsonInfo.results[0].weather_data[0].weather + "。<br/>天气"
			+ jsonInfo.results[0].index[0].zs + ", "
			+ jsonInfo.results[0].index[0].des

	$("#todayDetail").html(todayDetailText);
	// 设置生活指南信息

	$("#travelDegree")
			.html(
					"<strong>" + jsonInfo.results[0].index[2].title
							+ ":</strong>&nbsp;&nbsp"
							+ jsonInfo.results[0].index[2].zs);
	$("#travelDes").text(jsonInfo.results[0].index[2].des);
	$("#ultravioletDegree")
			.html(
					"<strong>" + jsonInfo.results[0].index[4].title
							+ ":</strong>&nbsp;&nbsp"
							+ jsonInfo.results[0].index[4].zs);
	$("#ultravioletDes").text(jsonInfo.results[0].index[4].des);

}

/**
 * 点击搜索按钮，执行搜索
 * 
 * @author Benny Yang
 * @since 20161123
 */
function clickSearch() {

	var myValue = $("#suggestId").val();
	setPlace(myValue);

}

/**
 * 响应enter键发起搜索
 */
function keyPressSearch() {

	var myValue = $("#suggestId").val();
	// alert("test--->"+myValue);
	setPlace(myValue);
}

function searchDriving() {

	map.clearOverlays();
	var driving = new BMap.DrivingRoute(map, {
		renderOptions : {
			map : map,
			panel : "xx",
			autoViewport : true
		},
		onPolylinesSet : function(routes) {

			map.clearOverlays();
			for (var i = 0; i < routes.length; i++) {

				var polyLineI = routes[i].getPolyline();
				polyLineI.setStrokeOpacity(0.6);
				polyLineI.setStrokeWeight(10);
				polyLineI.setStrokeColor('BLUE');
				map.addOverlay(polyLineI);

			}

		}
	});

	var start = $("#start").val();
	var end = $("#end").val();

	// alert(start + "---" + end);
	driving.search(start, end);
}

function chooseItem(obj) {

	// alert($(".leftContentli:last").text());
	// alert("nihao");
	// var choosedInfo = $(obj).find("div:first").find("div:first").text();
	// var choosedInfo = $(obj).text();
	var choosedInfo = $(obj).find("span:eq(0)").text();

	$(".leftContentDiv").attr("style", "margin-top: 20px;margin-left:10px")
	$(".leftContentDiv")
			.append(
					"<li class='leftContentli' style='list-style-type:square;font-size:14px;color:blue ;'><font class='choosedInfoClass'>"
							+ choosedInfo
							+ "</font>&nbsp;&nbsp;<font style='color:red;font-size:6px;cursor:pointer;' onclick='deleteOp(this);'>删除</font></li>");
	/*
	 * $("#leftDiv") .html("<ul type='square'>" + this.val() + "</ul>");
	 */
}

/**
 * 删除选定的条目
 * 
 * @author everlo
 * @since 20170227
 */
function deleteOp(obj) {

	if (!confirm("确认删除所选项？")) {

		return false;

	}
	$(obj).parent("li").remove();
}

/**
 * 响应搜索button，发起全程路径搜索
 * 
 */

var searchResult = null;

function searchClick() {

	// 点击线路规划首先清空上次的结果
	$("#xx").empty();
	map.clearOverlays();
	var choosedItemArray = new Array();
	// 获取选定的条目
	$("font.choosedInfoClass").each(function(key, value) {

		choosedItemArray[key] = $(this).text();

	});
	var mulStart = choosedItemArray[0];
	var mulEnd = choosedItemArray[choosedItemArray.length - 1];

	var asas = choosedItemArray.slice(1, choosedItemArray.length - 1);
	

	var driving = new BMap.DrivingRoute(map, {
		renderOptions : {
			map : map,
			panel : "xx",
			autoViewport : true,
			highlightMode : BMAP_HIGHLIGHT_ROUTE
		},
		onSearchComplete:function(results){
			
//			searchResult = JSON.stringify(results);
			searchResult = results;	
			console.log("多点检索结果如下：" + searchResult);
		},
		onResultsHtmlSet:function(container){
			
//			var onclickFunc = $('.navtrans-table>tbody>tr:first'); 	
			var onclickFunc = $('.navtrans-table>tbody>tr:first').attr("onclick");
			
			var onclickFuncBody = onclickFunc.substring(0,24);
//			alert("方法主题名为：" + onclickFuncBody);
			
//			alert("方法为：" + onclickFunc);
			$(".navtrans-res").html('<table class=navtrans_res_table><tbody></tbody></table>');//展示搜索结果的table
			/*for(var i=0;i<choosedItemArray.length;i++){
				
				var iconTr1 = "<tr><td><span class='round-tr'></span><div class='round-tr-content'>...</div></td></tr>";
				var iconTr2 = "<tr><td><span  class='arrow-tr'></span><div class='arrow-tr-content'>////</div></td></tr>";
				$('.navtrans_res_table tbody').append(iconTr1 + iconTr2);
			}*/
			
			var preStepLength = 0;
			for(var i=0; i<searchResult.sr[0].dk.length; i++){
				
				if(i>=1){
					
					preStepLength += searchResult.sr[0].dk[i-1].Nr.length;
				}
				for(var j=0; j<searchResult.sr[0].dk[i].Nr.length;j++){
					
					var currFunc = '_select(' +(preStepLength + j + 1)+ ')';
					
					var tempTr = "<tr class='"+('tr'+i)+"' id='" +('tr_'+i+j)+ "' style='cursor:pointer' onclick='" +(onclickFuncBody+currFunc)+ "'><td style='border-bottom:1px solid #E4E6E7;padding:10px;line-height:20px;'>" +searchResult.sr[0].dk[i].Nr[j].dl+ "</td></tr>";
					$('.navtrans_res_table tbody').append(tempTr);
				}
			}
			/*alert("是否变量在作用域：" + searchResult);
//			alert("获取的经纬度为：{" + searchResult.sr[0].dk[0].Nr[0].Uh.lng + "," + searchResult.sr[0].dk[0].Nr[0].Uh.lat + "}");
//			alert("获取的经纬度为：{" + searchResult.sr[0] +"}");
			var point = new BMap.Point(searchResult.sr[0].dk[0].Nr[0].Uh.lng,searchResult.sr[0].dk[0].Nr[0].Uh.lat);
			var gc = new BMap.Geocoder();
			gc.getLocation(point, function(rs){
			   var addComp = rs.addressComponents;
			   alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
			   alert(rs.address);
			});*/
			
//			var myhtml = '<></>';
//			$(".navtrans-table").html("我已经去掉了内容<br/>...我已经去掉了内容<br/>我已经去掉了内容<br/>我已经去掉了内容<br/>我已经去掉了内容<br/>");
//			$(".navtrans-res").html("我已经去掉了内容<br/>...我已经去掉了内容<br/>我已经去掉了内容<br/>我已经去掉了内容<br/>我已经去掉了内容<br/>");
//			$(".navtrans-res").html('');
			/*for(var i=0;i<searchResult;i++){
				
				
			}*/
		}
	/*
	 * , onPolylinesSet:function(routes){
	 * 
	 * map.clearOverlays(); for(var i=0;i<routes.length;i++){
	 * 
	 * var polyLineI = routes[i].getPolyline(); polyLineI.setStrokeOpacity(0.6);
	 * polyLineI.setStrokeWeight(10); polyLineI.setStrokeColor('BLUE');
	 * map.addOverlay(polyLineI);
	 *  } }
	 */
	});
	driving.search(mulStart, mulEnd, {
		waypoints : asas
	});// waypoints表示途经点

	/*
	 * var routePlanArray = new Array();// 保存查询结果方案 // 遍历选中的条路，进行线路查询 for (var i =
	 * 0; i < choosedItemArray.length - 1; i++) {
	 * 
	 * var itemI = choosedItemArray[i];// 线路起点 var itemI1 = choosedItemArray[i +
	 * 1];// 线路终点 // alert("当前起点：" + itemI + "----->" + "终点：" + itemI1); var
	 * driving = new BMap.DrivingRoute( map, { renderOptions : { // panel :
	 * "xx", autoViewport : false, hightlightModes : BMAP_HIGHLIGHT_STEP, },
	 * onSearchComplete : function(results) { //
	 * alert(results.getStart().title); // 需要获取方案数
	 * routePlanArray.push(results);// 将每一段结果保存起来，在全部检索完成之后自定义展示 //
	 * alert("当前线路方案数目：" + routePlanArray.length); if (routePlanArray.length ==
	 * choosedItemArray.length - 1) {// 已经完全获取到了全部数据 //
	 * alert(routePlanArray.length + // "<-------->jkkjkjjgggg"); //
	 * 展示所有选定地点的驾车路线 var appendedHTML = ""; for (var ia = 0; ia <
	 * routePlanArray.length; ia++) {// 几段路线数组
	 * 
	 * var subStart = routePlanArray[ia].getStart().title; var subEnd =
	 * routePlanArray[ia].getEnd().title; // alert("subStart:" +subStart+
	 * "----subEnd:" + // subEnd); appendedHTML = appendedHTML + ("<div
	 * class='subStep'><div class='subStart'><font color='blue'>" + subStart + "</font></div><div
	 * class='subDetail'>"); var subPlan = routePlanArray[ia].getPlan(0); var s =
	 * "";
	 * 
	 * var subRoute = subPlan.getRoute(0); for (var i1 = 0; i1 <
	 * subRoute.getNumSteps(); i1++) { var subStep = subRoute.getStep(i1); s = s +
	 * (i1 + 1) + ". " + subStep.getDescription() + "<br/>"; } appendedHTML =
	 * appendedHTML + s + "</div><div class='subEnd'><font color='blue'>" +
	 * subEnd + "</font></div>"; } // alert("html内容：" + appendedHTML);
	 * $("#xx").append(appendedHTML); // 完成内容读取显示之后，需要将选定条目等数据实体清空 appendedHTML =
	 * ""; choosedItemArray.splice(0, choosedItemArray.length);
	 * routePlanArray.splice(0, routePlanArray.length); } } });
	 * driving.search(itemI, itemI1);
	 */

	// alert("routePlanArray....:" + routePlanArray.length);
}

function GetQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");

	// alert(window.location.search);//返回的是url的参数
	var r = window.location.search.substr(1).match(reg);
	if (r != null)
		return decodeURI(r[2]);
	return null;
}

/**
 * 根据传入的查询信息查询周边信息，整合周边景点，餐饮，住宿
 */
function getNearPoi(containerId, keyWord, area) {

	map.clearOverlays();
	var localComm = new BMap.LocalSearch(map, {
		renderOptions : {
			map : map,
			// panel : "jingdianListDiv"
			panel : containerId
		},
		onResultsHtmlSet : function(container) {

			$(container).find("li>div").attr("onclick", "chooseItem(this);");
		},
		pageCapacity : 10
	});
	localComm.searchNearby(keyWord, centerPP, area);
}

/**
 * 检索附近周边信息数据，封装传递
 */
function getNearPoiData(keyWord, area) {

	searchLocalArr = [];
	// 定义每一页结果加载完成的回调函数
	function onSearchComplete1(results) {
		var totalResults = results.getNumPois();

		var totalPages = results.getNumPages();
		var currPage = results.getPageIndex();// 获取当前是第几页数据
		// alert("当前页码：总记录数：总页数["+currPage +':'+ totalResults +':'+ totalPages);
		for (var i = 0; i < results.getCurrentNumPois(); i++) {
			var currPoi = results.getPoi(i);
			searchLocalArr[currPage * 100 + i] = currPoi;
		}

		if (results.getPageIndex() < results.getNumPages() - 1) {
			local11.gotoPage(results.getPageIndex() + 1);
		} else {
			
			var data = JSON.stringify(searchLocalArr);
//			console.log(data);
			$.post("../servlet/spotService",{collectedData:data},function(dealedData){
				
				console.log(dealedData);
				
			});
		}
	}
	var local11 = new BMap.LocalSearch(map);
	local11.setSearchCompleteCallback(onSearchComplete1);
	local11.setPageCapacity(100);
	local11.searchNearby(keyWord, centerPP, area);

}

/**
 * 废弃
 */
/*
 * function ResultPoi(poiTitle, poiPoint, poiUrl, poiAddress, poiPhoneNumber,
 * poiIsAccurate, poiTags, poiDetailUrl) {
 * 
 * this.poiTitle = poiTitle;
 * 
 * this.poiPoint = poiPoint; this.poiUrl = poiUrl; this.poiAddress = poiAddress;
 * this.poiPhoneNumber = poiPhoneNumber; this.poiIsAccurate = poiIsAccurate;
 * this.poiTags = poiTags; this.poiDetailUrl = poiDetailUrl; }
 */